<template>
  <el-dialog
    top="30px"
    append-to-body
    title="项目信息"
    width="800px"
    :visible.sync="visible"
    :close-on-click-modal="false"
    :before-close="beforeClose"
  >
    <el-form :inline="true">
      <el-form-item>
        <select-address
          v-model="params.address_code"
          clearable
          auto-top
          @change="getData()"
          placeholder="地址查询"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          clearable
          @keyup.enter.native="getData()"
          placeholder="主体名称"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getData()">查询</el-button>
      </el-form-item>
    </el-form>

    <c-table border class="table-sm" v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <div class="text-truncate" :title="scope.row.address">{{ scope.row.address }}</div>
      </template>
    </c-table>
    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>
  </el-dialog>
</template>

<script>
import SelectAddress from '@/components/select/SelectAddress'
import { mapGetters } from 'vuex'
export default {
  components: {
    SelectAddress,
  },
  props: {
    visible: Boolean,
    serviceId: String,
  },
  data() {
    return {
      order: {
        create_time: 'asc',
      },
      params: {
        index: 1,
        size: 10,
        'gua_type.in': '1,4',
      },
      tableName: 'customer_related',
      tableData: [],
      tableColumns: [
        { attrs: { label: '主体名称', prop: 'customer_name' } },
        { attrs: { label: '地址', prop: 'address' }, slot: 'address' },
        { attrs: { label: '贷款银行', prop: 'bank_name' } },
        { attrs: { label: '放款金额', prop: 'reply_funds' } },
      ],
      totalCount: 0,
      loading: false,
    }
  },
  computed: {
    ...mapGetters(['clientId']),
    // orgLever() {
    //   return +this.user.orgRegionLever
    // }
  },
  watch: {
    serviceId() {
      this.setParams()
      this.getData()
    },
  },
  created() {
    this.setParams()
    this.getData()
  },
  methods: {
    setParams() {
      this.params['orWhereAnd.recommend_service.eq'] = this.clientId
      this.params['orWhereAnd.service_id.eq'] = this.serviceId

      this.params['orWhereAnd.service_id.in'] = this.clientId
      this.params['orWhereAnd.recommend_service.in'] = this.serviceId
    },
    getData(index = 1) {
      this.params.index = index
      this.loading = true
      this.$api
        .getData(this.$serviceName, this.tableName, this.params)
        .then(res => {
          const data = (res && res.data) || {}
          this.tableData = data.data
          this.totalCount = data.totalCount
        })
        .finally(() => {
          this.loading = false
        })
    },
    beforeClose() {
      this.$emit('update:visible', false)
    },
  },
}
</script>
<style lang="scss" scoped></style>
